home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-12 | 4.9 KB | 133 lines | [TEXT/CCL2] |
- ;;;
- ;;; draw-arrow.lisp
- ;;;
-
- #|
- ================================================================
- Purpose ========================================================
- ================================================================
- Defines the draw-arrow function. Contributed by seth@aic.hrl.hac.com .
- Modified by Matthew Cornell, cornell@cs.umass.edu.
-
-
- ================================================================
- Status =========================================================
- ================================================================
- Usable.
-
- Bug: Doesn't check (window-color-p (view-window view)) or *color-available* .
-
-
- ================================================================
- Change history =================================================
- ================================================================
- 11-Aug-92 mc Created from seth@aic.hrl.hac.com's source.
- Removed Quickdraw.lisp dependencies.
- Fixed color passing.
- Made into a view method.
- Moved draw-triangle into a labels.
- Passing color, macptr-pattern, and num-arrow-length keywords.
-
- |#
-
-
- (in-package "CCL")
-
- (export '(DRAW-ARROW
- )
- "CCL")
-
-
- ;;;================================================================
- ;;; Define the draw-arrow function and friends.
- ;;;================================================================
-
- (defgeneric draw-arrow (view pt-start pt-end
- &key color num-arrow-length
- macptr-pattern)
- (:documentation "Draws an arrow in view from pt-start to pt-end. The
- keywords customize its size and appearance."))
-
-
- (defmethod draw-arrow ((view view)
- (pt-start integer)
- (pt-end integer)
- &key (color *black-color*)
- (num-arrow-length 16.0)
- (macptr-pattern *black-pattern*))
- (labels ((draw-triangle (pt-end p2 p3 &aux poly)
- (setq poly (#_openpoly :ptr))
- (#_moveto :long pt-end)
- (#_lineto :long p2)
- (#_lineto :long p3)
- (#_lineto :long pt-end)
- (#_closepoly)
- (#_paintpoly :ptr poly)
- (#_killpoly :ptr poly)))
- (let* ((xdiff (- (point-h pt-end) (point-h pt-start)))
- (ydiff (- (point-v pt-end) (point-v pt-start)))
- (ang (if (zerop ydiff)
- (if (< xdiff 0) 4.7124 1.5708) ; 3/2 pi or 1/2 pi
- (atan (/ xdiff ydiff))))
- (angdiff (if (< ydiff 0) 0.25 2.8916))
- (ang1 (+ ang angdiff))
- (ang2 (- ang angdiff))
- (p2 (make-point (+ (round (* num-arrow-length (sin ang1))) (point-h pt-end))
- (+ (round (* num-arrow-length (cos ang1))) (point-v pt-end))))
- (p3 (make-point (+ (round (* num-arrow-length (sin ang2))) (point-h pt-end))
- (+ (round (* num-arrow-length (cos ang2))) (point-v pt-end)))))
- (with-focused-view view
- (with-fore-color color
- (with-pen-saved
- (#_PenPat macptr-pattern)
- (#_MoveTo :long pt-start)
- (#_LineTo :long pt-end)
- (draw-triangle pt-end p2 p3)))))))
-
-
- ;;; Done.
-
- (provide "DRAW-ARROW")
-
-
- #|;;; Define testing functions.
-
- (defun select-randomly-from-sequence (sequence)
- "Returns a randomly-selected element from sequence."
- ;;
- (elt sequence (random (length sequence))))
-
-
- (defun test-draw-arrow ()
- "Draws arrows while the mouse is down."
- ;;
- (let* ((view (make-instance 'window :window-title "Test Draw Arrow"
- :view-size #@(400 300))))
- (defmethod view-click-event-handler ((view (eql view))
- (pt-where integer))
- (let ((pt-center (make-point (round (point-h (view-size view)) 2)
- (round (point-v (view-size view)) 2)))
- (num-arrow-length (+ 5 (random 20)))
- (macptr-pattern
- (select-randomly-from-sequence
- (list *BLACK-PATTERN* *DARK-GRAY-PATTERN* *GRAY-PATTERN*
- *LIGHT-GRAY-PATTERN* ;*WHITE-PATTERN*
- )))
- (color
- (select-randomly-from-sequence
- (list *BLACK-COLOR* *BLUE-COLOR* *BROWN-COLOR* *DARK-GRAY-COLOR*
- *DARK-GREEN-COLOR* *GRAY-COLOR* *GREEN-COLOR*
- *LIGHT-BLUE-COLOR* *LIGHT-GRAY-COLOR* *ORANGE-COLOR*
- *PINK-COLOR* *PURPLE-COLOR* *RED-COLOR* *TAN-COLOR*
- ;*WHITE-COLOR*
- *YELLOW-COLOR*))))
- (rlet ((macptr-rect :rect :topLeft #@(0 0)
- :bottomRight (view-size view)))
- (#_EraseRect macptr-rect))
- (loop while (#_StillDown) do
- (draw-arrow view pt-center (view-mouse-position view)
- :color color :macptr-pattern macptr-pattern
- :num-arrow-length num-arrow-length))))
- ;;
- view))
- |#